/*
 * bw_public.h
 *
 *  Created on: 2018年9月4日
 *  Author: Degang.Wu (windragon@126.com)
 *  Desc:
 */

#ifndef BW_PUBLIC_H_
#define BW_PUBLIC_H_

#include <locale>
#include <string>
#include <list>
#include <vector>
#include <deque>
#include <map>
#include <sstream>
#include <fstream>
#include <exception>
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <cctype>
#include "../../hiapp/inc/public.h"

#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <stdarg.h>
#include <errno.h>
#include <dirent.h>
#include <ctype.h>
#include <signal.h>
#include <termios.h>
#include <stdint.h>
#include <stdio.h>
#include <iconv.h>
#include <execinfo.h>
#include <assert.h>
#include <resolv.h>
#include <math.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/vfs.h>
#include <sys/sysinfo.h>
#include <sys/resource.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/epoll.h>
#include <sys/shm.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <linux/unistd.h>
#include <sys/syscall.h>
#include <net/if.h>
#include <net/route.h>

#include "bw_errno.h"

#ifndef attribute_deprecated
#define attribute_deprecated __attribute__((deprecated))
#endif

#define BWFCGI_WRONG_RESP	"{\"retCode\":1,\"retMsg\":\"INVALID REQUEST\",\"retData\":{}}"

#define 	BWENC_DATABASE	"encoder.db"

#define		BWENC_WEBFILE	"www"
//#define		BWENC_WEBFILE	"osd"

#define		BWENC_PIC_MAX_W 1920
#define		BWENC_PIC_MAX_H	1080
#define		BWENC_FONT_SIZE_MAX 28
#define		BWENC_FONT_SIZE_MIN 8
#define		BWENC_SUB_LEN_MAX 256
#define		BWENC_QR_TEXT_LEN_MAX 128
#define		BWENC_OUT_LOG_NUM	10000
#define		BWENC_OSD_SLIDE_INTERVAL_MAX	3600
#define		BWENC_PORT_MAX 65535

#define SAFE_AVFREE_PTR(p)\
do {	\
	if (p) {	\
		av_free(p);	\
		p = NULL;	\
	}	\
}while (0)

#define BW_RAM_LOG_PATH		"/var/log/ramfs"


namespace bwcgi {

typedef struct _st_path_
{
    char dir[MAX_PATH];
    char file[MAX_PATH];
}PATH;

typedef struct _page_query
{
	int 	page;
	int 	count;
}PAGE_QUERY;

int get_g_oubuf_size();

int FCGI_file_exist(const char *fname);
int FCGI_file_size(const char *fname);
void FCGI_file_split(PATH* rpath, const char* fullpath);
void FCGI_file_write(const char* fname, const char* buf, int buf_len);
int FCGI_file_read(const char* fname, U8* buf, int buf_len);

#define FCGI_log(format, ...) \
		_FCGI_log("[%s %d:%s] " format, \
		__FILE__, __LINE__, __func__, ##__VA_ARGS__ )
int _FCGI_log(const char *format, ...);

int FCGI_is_multicast(U32 ipaddr);

int FCGI_set_core_path(const char *path);

const char* bwenc_common_ack(eENC_ERROR code);
char* FCGI_module_folder(void);

int FCGI_shell_exec(const char* cmdline, char* out, size_t out_len);

unsigned int Addr_swap(unsigned int uiaddr);

char *iptostr(unsigned int ip);

unsigned int ipstrtoint(char *val_str);
}  // namespace bwcgi

#ifdef __cplusplus
}
#endif

#endif /* BW_PUBLIC_H_ */
